package com.example.tool;

import com.example.domain.user;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class CreatJwt {
    public static String getToken(user u){
        Jwts.builder();//生成
        Jwts.parser();//解密

        JwtBuilder jwtBuilder=Jwts.builder()
                .setId(u.getUser_id())//设置需要加密的内容
                .setSubject(u.getUser_pw())
                .setIssuedAt(new Date())//token保留时间
                .signWith(SignatureAlgorithm.HS256,"my-123").setExpiration(
                        new Date(new Date().getTime()+86400000)
                );
        //System.out.println("token值：" +jwtBuilder.compact());
        return jwtBuilder.compact();
    }

}
